﻿using DCIMAP.GANS.GeneticAlgorithms.Kit;
using DCIMAP.GANS.GeneticAlgorithms.Legacy;
using GAIQ;
using System;
using System.Collections.Generic;
using System.Text;


[System.Serializable]
public class IQMutator : ArrayMutator
{
    /// <summary>
    /// Функция возвращает элемент, на котороый надо поменять gene[position]!!!!
    /// </summary>
    static Random _r = new Random();

      public override object Mutate(ArrayGene gene1, int position)
    {
           StringArrayGene gene = (StringArrayGene)gene1;
          string sumbol = gene.StringCode[position];
          object s_r;
          int n;
          switch (sumbol)
          {
            case "1":  n = _r.Next(2);
                  if (n == 0) { s_r = "x"; }
                  else { s_r = "y"; }                
                break;
            case "x": n = _r.Next(2);
                if (n == 0) { s_r = "1"; }
                else { s_r = "y"; }
                break;
            case "y": n = _r.Next(2);
                if (n == 0) { s_r = "1"; }
                else { s_r = "x"; }
                break;
            default: n = _r.Next(ListOp.getLength());
                while (ListOp.getSymbols()[n] == sumbol) {n = _r.Next(ListOp.getLength());}
                s_r = ListOp.getSymbols()[n];
                break;        
          }
          
        return s_r;

    }
}